package com.galen.config;

import com.google.code.kaptcha.Producer;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * 图形验证码使用
 *
 * @author GalenGao
 * @version Id: KaptchaConfig.java, v 0.1 2022/6/20 12:06 GalenGao Exp $$
 */
@Configuration
public class KaptchaConfig {

    /**
     * 验证码配置
     * @return Producer
     */
    @Bean
    public Producer producer() {
        Properties properties = new Properties();
        properties.setProperty("kaptcha.image.width", "150");
        properties.setProperty("kaptcha.image.weight", "150");
        properties.setProperty("kaptcha.textproducer.char.string", "0123456789qwertyuioplkjhgfdsazxcvbnm");
        properties.setProperty("kaptcha.textproducer.char.length", "6");
        Config config = new Config(properties);
        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
        defaultKaptcha.setConfig(config);
        return defaultKaptcha;
    }
}
